package com.youlai.boot.config;


import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.dialect.DbType;
import com.mybatisflex.core.dialect.DialectFactory;
import com.mybatisflex.core.logicdelete.LogicDeleteManager;
import com.mybatisflex.core.logicdelete.LogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.DateTimeLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.IntegerLogicDeleteProcessor;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import com.youlai.boot.common.listener.CreatedByListener;
import com.youlai.boot.common.listener.CreatedByListenerFlag;
import com.youlai.boot.common.listener.UpdatedByListener;
import com.youlai.boot.common.listener.UpdatedByListenerFlag;
import com.youlai.boot.core.handler.DataPermissionDialectHandler;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Log4j2
public class MybatisFlexConfiguration implements MyBatisFlexCustomizer {
    @Override
    public void customize(FlexGlobalConfig config) {
        config.registerInsertListener(new CreatedByListener(), CreatedByListenerFlag.class);
        config.registerUpdateListener(new UpdatedByListener(), UpdatedByListenerFlag.class);

        // 注册数据权限
        DialectFactory.registerDialect(DbType.MYSQL,new DataPermissionDialectHandler());
    }

}
